package com.ruoyi.web.controller.carrepairmanage;

import com.ruoyi.car.domain.CarManage;
import com.ruoyi.car.domain.CatRepair;
import com.ruoyi.car.domain.CatUpkeep;
import com.ruoyi.car.service.ICarManageService;
import com.ruoyi.car.service.ICatUpkeepService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
     * 车辆管理Controller
     *
     * @author ruoyi
     * @date 2020-06-18
     */
    @Controller
    @RequestMapping("/ruoyi/carupkeep")
    public class CarUpKeepManageController extends BaseController
    {
        private String prefix = "ruoyi/manages";

        @Autowired
        private ICarManageService carManageService;
        @Autowired
        private ICatUpkeepService catUpkeepService;

        @RequiresPermissions("ruoyi:carupkeep:view")
        @GetMapping()
        public String manages()
        {
            return prefix + "/upkeepmanages";
        }

        /**
         * 查询车辆管理
         列表
         */
        @RequiresPermissions("ruoyi:manages:list")
        @PostMapping("/list")
        @ResponseBody
        public TableDataInfo list(CarManage carManage)
        {
            startPage();
            List<CarManage> list = carManageService.selectCarManageList(carManage);
            return getDataTable(list);
        }

        /**
         * 查询车辆维修管理列表
         */
        @RequiresPermissions("ruoyi:manages:lists")
        @PostMapping("/lists/{cCarid}")
        @ResponseBody
        public TableDataInfo lists(@PathVariable("cCarid") String cCarid, CatUpkeep catUpkeep)
        {
            catUpkeep.setcCarld(cCarid);
            startPage();
            List<CatUpkeep> lists = catUpkeepService.selectCat(catUpkeep);
            return getDataTable(lists);
        }
        /**
         * 修改【请填写功能名称】
         */
        @GetMapping("/edit/{cId}")
        public String edit(@PathVariable("cId") Long cId, ModelMap mmap)
        {
            CatUpkeep catUpkeep = catUpkeepService.selectCatUpkeepById(cId);
            mmap.put("catUpkeep", catUpkeep);
            return prefix + "/edit";
        }

        /**
         * 修改保存【请填写功能名称】
         */
        @RequiresPermissions("ruoyi:manages:edit")
        @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
        @PostMapping("/edit")
        @ResponseBody
        public AjaxResult editSave(CatUpkeep catUpkeep)
        {
            return toAjax(catUpkeepService.updateCatUpkeep(catUpkeep));
        }

        @GetMapping("/detail/{cCarid}")
        public String detail(@PathVariable("cCarid") String cCarid, ModelMap map) {
            map.put("cCarid", cCarid);
            return prefix + "/upkeepdetail";
        }

    }
